dafe003e731ea04c3ac157156649c403abfe607c
3 * A special page to search for files by MIME type as defined in the
4 * img_major_mime and img_minor_mime fields in the image table
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
14 * Searches the database for files of the requested MIME type, comparing this with the
15 * 'img_major_mime' and 'img_minor_mime' fields in the image table.
16 * @ingroup SpecialPage
18 class MIMEsearchPage
extends QueryPage
{
21 function MIMEsearchPage( $major, $minor ) {
22 $this->major
= $major;
23 $this->minor
= $minor;
26 function getName() { return 'MIMEsearch'; }
29 * Due to this page relying upon extra fields being passed in the SELECT it
30 * will fail if it's set as expensive and misermode is on
32 function isExpensive() { return true; }
33 function isSyndicated() { return false; }
35 function linkParameters() {
36 $arr = array( $this->major
, $this->minor
);
37 $mime = implode( '/', $arr );
38 return array( 'mime' => $mime );
42 $dbr = wfGetDB( DB_SLAVE
);
43 $image = $dbr->tableName( 'image' );
44 $major = $dbr->addQuotes( $this->major
);
45 $minor = $dbr->addQuotes( $this->minor
);
48 "SELECT 'MIMEsearch' AS type,
49 " . NS_FILE
. " AS namespace,
51 img_major_mime AS value,
59 WHERE img_major_mime = $major AND img_minor_mime = $minor
63 function formatResult( $skin, $result ) {
64 global $wgContLang, $wgLang;
66 $nt = Title
::makeTitle( $result->namespace, $result->title
);
67 $text = $wgContLang->convert( $nt->getText() );
69 Title
::newFromText( $nt->getPrefixedText() ),
70 htmlspecialchars( $text )
73 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
74 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
75 $wgLang->formatNum( $result->img_size
) );
76 $dimensions = htmlspecialchars( wfMsg( 'widthheight',
77 $wgLang->formatNum( $result->img_width
),
78 $wgLang->formatNum( $result->img_height
)
80 $user = $skin->link( Title
::makeTitle( NS_USER
, $result->img_user_text
), htmlspecialchars( $result->img_user_text
) );
81 $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp
) );
83 return "($download) $plink . . $dimensions . . $bytes . . $user . . $time";
88 * Output the HTML search form, and constructs the MIMEsearchPage object.
90 function wfSpecialMIMEsearch( $par = null ) {
91 global $wgRequest, $wgOut;
93 $mime = isset( $par ) ?
$par : $wgRequest->getText( 'mime' );
96 Xml
::openElement( 'form', array( 'id' => 'specialmimesearch', 'method' => 'get', 'action' => SpecialPage
::getTitleFor( 'MIMEsearch' )->getLocalUrl() ) ) .
97 Xml
::openElement( 'fieldset' ) .
98 Xml
::hidden( 'title', SpecialPage
::getTitleFor( 'MIMEsearch' )->getPrefixedText() ) .
99 Xml
::element( 'legend', null, wfMsg( 'mimesearch' ) ) .
100 Xml
::inputLabel( wfMsg( 'mimetype' ), 'mime', 'mime', 20, $mime ) . ' ' .
101 Xml
::submitButton( wfMsg( 'ilsubmit' ) ) .
102 Xml
::closeElement( 'fieldset' ) .
103 Xml
::closeElement( 'form' )
106 list( $major, $minor ) = wfSpecialMIMEsearchParse( $mime );
107 if ( $major == '' or $minor == '' or !wfSpecialMIMEsearchValidType( $major ) )
109 $wpp = new MIMEsearchPage( $major, $minor );
111 list( $limit, $offset ) = wfCheckLimits();
112 $wpp->doQuery( $offset, $limit );
115 function wfSpecialMIMEsearchParse( $str ) {
116 // searched for an invalid MIME type.
117 if( strpos( $str, '/' ) === false) {
118 return array ('', '');
121 list( $major, $minor ) = explode( '/', $str, 2 );
124 ltrim( $major, ' ' ),
129 function wfSpecialMIMEsearchValidType( $type ) {
130 // From maintenance/tables.sql => img_major_mime
143 return in_array( $type, $types );